﻿using System;
using System.Collections;
using System.Collections.Generic;
//using IBatisNet.DataAccess;
using Wsitech.Model;

namespace Wsitech.BLL
{
    /// <summary>
    /// 功能：     RoleFuncRela业务逻辑实现
    /// 作者：     LI
    /// 日期：     5/16/2012
    /// </summary>
    public class RoleFuncRelaBLL
    {
        private Wsitech.Persistence.Interface.IRoleFuncRelaDao dao = null;

        private RoleFuncRelaBLL()
        {
            dao = Wsitech.Persistence.Dao.RoleFuncRelaSqlMapDao.Instance;
        }

        #region （懒汉）单例模式
        private static RoleFuncRelaBLL instance = null;
        private static object syncRoot = new object();
        public static RoleFuncRelaBLL Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new RoleFuncRelaBLL();
                        }
                    }
                }
                return instance;
            }
        }
        #endregion


        #region	基本功能 不能修改


        /// <summary>
        /// 根据主键得到明细
        /// </summary>
        /// <returns></returns>
        public RoleFuncRela GetDetail(System.String relaid)
        {
            try
            {
                return dao.GetDetail(relaid);
            }
            catch
            {
                throw;
            }
        }


        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public IList<RoleFuncRela> GetList()
        {
            try
            {
                IList<RoleFuncRela> list = dao.GetList();
                return list;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private IList<RoleFuncRela> GetListByParams(object TopCounts, RoleFuncRela rolefuncrela)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                IList<RoleFuncRela> list = dao.GetListByParams(ht);
                return list;
            }
            catch
            {
                throw;
            }
        }



        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="rolefuncrela"></param>
        /// <returns></returns>
        public object Add(RoleFuncRela rolefuncrela)
        {
            try
            {
                return dao.Add(rolefuncrela);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="rolefuncrela"></param>
        /// <returns></returns>
        public int Update(RoleFuncRela rolefuncrela)
        {
            try
            {
                return dao.Update(rolefuncrela);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="RelaId"></param>
        /// <returns></returns>
        public int Delete(System.String relaid)
        {
            try
            {
                return dao.Delete(relaid);
            }
            catch
            {
                throw;
            }
        }

        #endregion


        #region 扩展功能

        #endregion


        /// <summary>
        /// 根据角色ID查询关系
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public IList<RoleFuncRela> GetListByRoleId(string roleid)
        {
            Hashtable ht = new Hashtable();
            ht.Add("roleid", roleid);

            return dao.GetListByParams(ht);
        }

        /// <summary>
        /// 删除角色对应的所有权限
        /// </summary>
        public void DeleteByRoleId(string roleid)
        {
            dao.DeleteByRoleId(roleid);
        }
    }
}
